package com.huang.controller;

import com.huang.common.CommonResult;
import com.huang.entity.Film;
import com.huang.service.FilmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/film")
public class FilmController {

    @Resource
    private FilmService filmService;

    @GetMapping
    public List<Film> queryAll() {
        return filmService.queryAll();
    }

    @GetMapping("/{id}")
    public Film queryById(@PathVariable("id") Integer filmId) {
        return filmService.queryById(filmId);
    }

    @GetMapping("/title/{title}")
    public List<Film> queryByTitle(@PathVariable String title) {
        return filmService.queryByTitle(title);
    }


    @PostMapping
    public CommonResult addOne(@RequestBody Film film) {
        log.info("film is {}",film);
        filmService.addOne(film);
        return new CommonResult(200,"success",null);
    }

    @PutMapping
    public CommonResult modOne(@RequestBody Film film) {
        log.info("film is {}",film);
        filmService.modOne(film);
        return new CommonResult(200,"success",null);

    }

    @DeleteMapping("/{id}")
    public CommonResult removeOne(@PathVariable("id") Integer filmId) {
        filmService.removeOne(filmId);
        return new CommonResult(200,"success",null);

    }
}
